package model;

import java.sql.*;
import java.util.Date;
import dal.*;
import util.*;

public class EventModel implements IModel {

	public static class FieldNames {
		public static String Id = "Id";
		public static String IdProject = "IdProject";
		public static String Name = "Name";
		public static String Code = "Code";
		public static String Description = "Description";
		public static String IdTask = "IdTask";
		public static String IdType = "IdType";
		public static String IdPlace = "IdPlace";
		public static String IdVenue = "IdVenue";
		public static String PlanStartTime = "PlanStartTime";
		public static String PlanEndTime = "PlanEndTime";
		public static String RealStartTate = "RealStartTate";
		public static String RealEndTime = "RealEndTime";
		public static String NeedApproval = "NeedApproval";
		public static String IsEvent = "IsEvent";
		public static String Status = "Status";
		public static String IsDraft = "IsDraft";
		public static String Notification = "Notification";
		public static String Created = "Created";
		public static String Creator = "Creator";
		public static String Updated = "Updated";
		public static String Updator = "Updator";
		public static String Deleted = "Deleted";
		public static String DeletionTime = "DeletionTime";
	
	}

	public class ErrorMessages {
		public String Id = "";
		public String IdProject = "";
		public String Name = "";
		public String Code = "";
		public String Description = "";
		public String IdTask = "";
		public String IdType = "";
		public String IdPlace = "";
		public String IdVenue = "";
		public String PlanStartTime = "";
		public String PlanEndTime = "";
		public String RealStartTate = "";
		public String RealEndTime = "";
		public String NeedApproval = "";
		public String IsEvent = "";
		public String Status = "";
		public String IsDraft = "";
		public String Notification = "";
		public String Created = "";
		public String Creator = "";
		public String Updated = "";
		public String Updator = "";
		public String Deleted = "";
		public String DeletionTime = "";
	
	}

    public ErrorMessages errMsgs = new ErrorMessages();

	public String[] errMsgList = null;

// private variables
private int _id = Integer.MIN_VALUE;
private int _id_project = Integer.MIN_VALUE;
private String _name = null;
private String _code = null;
private String _description = null;
private int _id_task = Integer.MIN_VALUE;
private int _id_type = Integer.MIN_VALUE;
private int _id_place = Integer.MIN_VALUE;
private int _id_venue = Integer.MIN_VALUE;
private Date _plan_start_time = null;
private Date _plan_end_time = null;
private Date _real_start_tate = null;
private Date _real_end_time = null;
private boolean _need_approval = false;
private boolean _isneed_approvalSet = false;
private boolean _is_event = false;
private boolean _isis_eventSet = false;
private int _status = Integer.MIN_VALUE;
private boolean _is_draft = false;
private boolean _isis_draftSet = false;
private int _notification = Integer.MIN_VALUE;
private Date _created = null;
private int _creator = Integer.MIN_VALUE;
private Date _updated = null;
private int _updator = Integer.MIN_VALUE;
private boolean _deleted = false;
private boolean _isdeletedSet = false;
private Date _deletion_time = null;


	public EventModel() {
	}

// get/set
public int getId() {
		return _id;
	}
public void setId(int value) {
		_id = value;
	}
public String getIdToString() {
		if (_id == Integer.MIN_VALUE
				|| _id == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id);
		}
	}
public int getIdProject() {
		return _id_project;
	}
public void setIdProject(int value) {
		_id_project = value;
	}
public String getIdProjectToString() {
		if (_id_project == Integer.MIN_VALUE
				|| _id_project == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_project);
		}
	}
public String getName() {
		return _name;
	}
public void setName(String value) {
		_name = value;
	}
public String getNameToString() {
		if (_name != null) {
			return HtmlUtil.genHtml(_name);
		} else {
			return "";
		}
	}
public String getCode() {
		return _code;
	}
public void setCode(String value) {
		_code = value;
	}
public String getCodeToString() {
		if (_code != null) {
			return HtmlUtil.genHtml(_code);
		} else {
			return "";
		}
	}
public String getDescription() {
		return _description;
	}
public void setDescription(String value) {
		_description = value;
	}
public String getDescriptionToString() {
		if (_description != null) {
			return HtmlUtil.genHtml(_description);
		} else {
			return "";
		}
	}
public int getIdTask() {
		return _id_task;
	}
public void setIdTask(int value) {
		_id_task = value;
	}
public String getIdTaskToString() {
		if (_id_task == Integer.MIN_VALUE
				|| _id_task == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_task);
		}
	}
public int getIdType() {
		return _id_type;
	}
public void setIdType(int value) {
		_id_type = value;
	}
public String getIdTypeToString() {
		if (_id_type == Integer.MIN_VALUE
				|| _id_type == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_type);
		}
	}
public int getIdPlace() {
		return _id_place;
	}
public void setIdPlace(int value) {
		_id_place = value;
	}
public String getIdPlaceToString() {
		if (_id_place == Integer.MIN_VALUE
				|| _id_place == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_place);
		}
	}
public int getIdVenue() {
		return _id_venue;
	}
public void setIdVenue(int value) {
		_id_venue = value;
	}
public String getIdVenueToString() {
		if (_id_venue == Integer.MIN_VALUE
				|| _id_venue == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_venue);
		}
	}
public Date getPlanStartTime() {
		return _plan_start_time;
	}
public void setPlanStartTime(Date value) {
		_plan_start_time = value;
	}
public String getPlanStartTimeToString() {
		if (_plan_start_time != null) {
			return StringUtil.toDateTimeString(_plan_start_time);
		} else {
			return "";
		}
	}
public Date getPlanEndTime() {
		return _plan_end_time;
	}
public void setPlanEndTime(Date value) {
		_plan_end_time = value;
	}
public String getPlanEndTimeToString() {
		if (_plan_end_time != null) {
			return StringUtil.toDateTimeString(_plan_end_time);
		} else {
			return "";
		}
	}
public Date getRealStartTate() {
		return _real_start_tate;
	}
public void setRealStartTate(Date value) {
		_real_start_tate = value;
	}
public String getRealStartTateToString() {
		if (_real_start_tate != null) {
			return StringUtil.toDateTimeString(_real_start_tate);
		} else {
			return "";
		}
	}
public Date getRealEndTime() {
		return _real_end_time;
	}
public void setRealEndTime(Date value) {
		_real_end_time = value;
	}
public String getRealEndTimeToString() {
		if (_real_end_time != null) {
			return StringUtil.toDateTimeString(_real_end_time);
		} else {
			return "";
		}
	}
public boolean getNeedApproval() {
		return _need_approval;
	}
public void setNeedApproval(boolean value) {
		_need_approval = value;
		_isneed_approvalSet = true;
	}
public boolean getNeedApprovalSet() {
		return _isneed_approvalSet;
	}
	public String getNeedApprovalToString() {
		if (_isneed_approvalSet) {
			return HtmlUtil.genHtml(_need_approval);
		} else {
			return "";
		}
	}
public boolean getIsEvent() {
		return _is_event;
	}
public void setIsEvent(boolean value) {
		_is_event = value;
		_isis_eventSet = true;
	}
public boolean getIsEventSet() {
		return _isis_eventSet;
	}
	public String getIsEventToString() {
		if (_isis_eventSet) {
			return HtmlUtil.genHtml(_is_event);
		} else {
			return "";
		}
	}
public int getStatus() {
		return _status;
	}
public void setStatus(int value) {
		_status = value;
	}
public String getStatusToString() {
		if (_status == Integer.MIN_VALUE
				|| _status == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_status);
		}
	}
public boolean getIsDraft() {
		return _is_draft;
	}
public void setIsDraft(boolean value) {
		_is_draft = value;
		_isis_draftSet = true;
	}
public boolean getIsDraftSet() {
		return _isis_draftSet;
	}
	public String getIsDraftToString() {
		if (_isis_draftSet) {
			return HtmlUtil.genHtml(_is_draft);
		} else {
			return "";
		}
	}
public int getNotification() {
		return _notification;
	}
public void setNotification(int value) {
		_notification = value;
	}
public String getNotificationToString() {
		if (_notification == Integer.MIN_VALUE
				|| _notification == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_notification);
		}
	}
public Date getCreated() {
		return _created;
	}
public void setCreated(Date value) {
		_created = value;
	}
public String getCreatedToString() {
		if (_created != null) {
			return StringUtil.toDateTimeString(_created);
		} else {
			return "";
		}
	}
public int getCreator() {
		return _creator;
	}
public void setCreator(int value) {
		_creator = value;
	}
public String getCreatorToString() {
		if (_creator == Integer.MIN_VALUE
				|| _creator == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_creator);
		}
	}
public Date getUpdated() {
		return _updated;
	}
public void setUpdated(Date value) {
		_updated = value;
	}
public String getUpdatedToString() {
		if (_updated != null) {
			return StringUtil.toDateTimeString(_updated);
		} else {
			return "";
		}
	}
public int getUpdator() {
		return _updator;
	}
public void setUpdator(int value) {
		_updator = value;
	}
public String getUpdatorToString() {
		if (_updator == Integer.MIN_VALUE
				|| _updator == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_updator);
		}
	}
public boolean getDeleted() {
		return _deleted;
	}
public void setDeleted(boolean value) {
		_deleted = value;
		_isdeletedSet = true;
	}
public boolean getDeletedSet() {
		return _isdeletedSet;
	}
	public String getDeletedToString() {
		if (_isdeletedSet) {
			return HtmlUtil.genHtml(_deleted);
		} else {
			return "";
		}
	}
public Date getDeletionTime() {
		return _deletion_time;
	}
public void setDeletionTime(Date value) {
		_deletion_time = value;
	}
public String getDeletionTimeToString() {
		if (_deletion_time != null) {
			return StringUtil.toDateTimeString(_deletion_time);
		} else {
			return "";
		}
	}


	@Override
	public int[] getPrimaryKey() {
		int[] ids = new int[1];
		ids[0] = getId();
		return ids;
	}

	@Override
	public IModel readFromResultSet(ResultSet rs) throws SQLException {
		EventModel model = null;

			model = new EventModel();

// read fields
{
				int value = rs.getInt("id");
				if (!rs.wasNull()) {
					model.setId(value);
				}
			}
{
				int value = rs.getInt("id_project");
				if (!rs.wasNull()) {
					model.setIdProject(value);
				}
			}
{
				String value = rs.getString("name");
				if (!rs.wasNull()) {
					model.setName(value);
				}
			}
{
				String value = rs.getString("code");
				if (!rs.wasNull()) {
					model.setCode(value);
				}
			}
{
				String value = rs.getString("description");
				if (!rs.wasNull()) {
					model.setDescription(value);
				}
			}
{
				int value = rs.getInt("id_task");
				if (!rs.wasNull()) {
					model.setIdTask(value);
				}
			}
{
				int value = rs.getInt("id_type");
				if (!rs.wasNull()) {
					model.setIdType(value);
				}
			}
{
				int value = rs.getInt("id_place");
				if (!rs.wasNull()) {
					model.setIdPlace(value);
				}
			}
{
				int value = rs.getInt("id_venue");
				if (!rs.wasNull()) {
					model.setIdVenue(value);
				}
			}
{
				Date value = rs.getTimestamp("plan_start_time");
				if (!rs.wasNull()) {
					model.setPlanStartTime(value);
				}
			}
{
				Date value = rs.getTimestamp("plan_end_time");
				if (!rs.wasNull()) {
					model.setPlanEndTime(value);
				}
			}
{
				Date value = rs.getTimestamp("real_start_tate");
				if (!rs.wasNull()) {
					model.setRealStartTate(value);
				}
			}
{
				Date value = rs.getTimestamp("real_end_time");
				if (!rs.wasNull()) {
					model.setRealEndTime(value);
				}
			}
{
				boolean value = rs.getBoolean("need_approval");
				if (!rs.wasNull()) {
					model.setNeedApproval(value);
				}
			}
{
				boolean value = rs.getBoolean("is_event");
				if (!rs.wasNull()) {
					model.setIsEvent(value);
				}
			}
{
				int value = rs.getInt("status");
				if (!rs.wasNull()) {
					model.setStatus(value);
				}
			}
{
				boolean value = rs.getBoolean("is_draft");
				if (!rs.wasNull()) {
					model.setIsDraft(value);
				}
			}
{
				int value = rs.getInt("notification");
				if (!rs.wasNull()) {
					model.setNotification(value);
				}
			}
{
				Date value = rs.getTimestamp("created");
				if (!rs.wasNull()) {
					model.setCreated(value);
				}
			}
{
				int value = rs.getInt("creator");
				if (!rs.wasNull()) {
					model.setCreator(value);
				}
			}
{
				Date value = rs.getTimestamp("updated");
				if (!rs.wasNull()) {
					model.setUpdated(value);
				}
			}
{
				int value = rs.getInt("updator");
				if (!rs.wasNull()) {
					model.setUpdator(value);
				}
			}
{
				boolean value = rs.getBoolean("deleted");
				if (!rs.wasNull()) {
					model.setDeleted(value);
				}
			}
{
				Date value = rs.getTimestamp("deletion_time");
				if (!rs.wasNull()) {
					model.setDeletionTime(value);
				}
			}
		

		return model;
	}

	@Override
	public PreparedStatement genSelectStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "SELECT * FROM sp_event_select(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

        EventModel obj = (EventModel )query;
		
// set parameters
st.setObject("id", obj.getId());


		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genSelectListStatement(Connection dbConn,
			IModelExt query) throws SQLException {
		String sql = "SELECT * FROM sp_event_selectList(:limit, :offset, :id,:id_project,:name,:code,:description,:id_task,:id_type,:id_place,:id_venue,:plan_start_timeFrom,:plan_start_timeTo,:plan_end_timeFrom,:plan_end_timeTo,:real_start_tateFrom,:real_start_tateTo,:real_end_timeFrom,:real_end_timeTo,:need_approval,:is_event,:status,:is_draft,:notification,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		EventModelExt obj = (EventModelExt) query;

		if (obj.getLimit() != Integer.MIN_VALUE) {
			st.setObject("limit", obj.getLimit());
		}  else {
			st.setObject("limit", Integer.MAX_VALUE);
		}
		if (obj.getOffset() != Integer.MIN_VALUE) {
			st.setObject("offset", obj.getOffset());
		}  else {
			st.setObject("offset", 0);
		}

// set parameters
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
            st.setObject("id", null);
}
if (obj.getIdProject() != Integer.MIN_VALUE) {
			st.setObject("id_project", obj.getIdProject());
		} else {
            st.setObject("id_project", null);
}
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
            st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
            st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
            st.setObject("description", null);
}
if (obj.getIdTask() != Integer.MIN_VALUE) {
			st.setObject("id_task", obj.getIdTask());
		} else {
            st.setObject("id_task", null);
}
if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
            st.setObject("id_type", null);
}
if (obj.getIdPlace() != Integer.MIN_VALUE) {
			st.setObject("id_place", obj.getIdPlace());
		} else {
            st.setObject("id_place", null);
}
if (obj.getIdVenue() != Integer.MIN_VALUE) {
			st.setObject("id_venue", obj.getIdVenue());
		} else {
            st.setObject("id_venue", null);
}
if (obj.getPlanStartTimeFrom() != null) {
			st.setObject("plan_start_timeFrom", obj.getPlanStartTimeFrom());
		} else {
			st.setObject("plan_start_timeFrom", null);
		}
		if (obj.getPlanStartTimeTo() != null) {
			st.setObject("plan_start_timeTo", obj.getPlanStartTimeTo());
		} else {
            st.setObject("plan_start_timeTo", null);
}
if (obj.getPlanEndTimeFrom() != null) {
			st.setObject("plan_end_timeFrom", obj.getPlanEndTimeFrom());
		} else {
			st.setObject("plan_end_timeFrom", null);
		}
		if (obj.getPlanEndTimeTo() != null) {
			st.setObject("plan_end_timeTo", obj.getPlanEndTimeTo());
		} else {
            st.setObject("plan_end_timeTo", null);
}
if (obj.getRealStartTateFrom() != null) {
			st.setObject("real_start_tateFrom", obj.getRealStartTateFrom());
		} else {
			st.setObject("real_start_tateFrom", null);
		}
		if (obj.getRealStartTateTo() != null) {
			st.setObject("real_start_tateTo", obj.getRealStartTateTo());
		} else {
            st.setObject("real_start_tateTo", null);
}
if (obj.getRealEndTimeFrom() != null) {
			st.setObject("real_end_timeFrom", obj.getRealEndTimeFrom());
		} else {
			st.setObject("real_end_timeFrom", null);
		}
		if (obj.getRealEndTimeTo() != null) {
			st.setObject("real_end_timeTo", obj.getRealEndTimeTo());
		} else {
            st.setObject("real_end_timeTo", null);
}
		if (obj.getNeedApprovalSet()) {
			st.setObject("need_approval", obj.getNeedApproval());
		} else {
            st.setObject("need_approval", null);
}
		if (obj.getIsEventSet()) {
			st.setObject("is_event", obj.getIsEvent());
		} else {
            st.setObject("is_event", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
            st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
            st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
            st.setObject("notification", null);
}
if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
            st.setObject("createdTo", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
            st.setObject("creator", null);
}
if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
            st.setObject("updatedTo", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
            st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
            st.setObject("deleted", null);
}
if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
            st.setObject("deletion_timeTo", null);
}
	

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genInsertStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_event_insert(:id_project,:name,:code,:description,:id_task,:id_type,:id_place,:id_venue,:plan_start_time,:plan_end_time,:real_start_tate,:real_end_time,:need_approval,:is_event,:status,:is_draft,:notification,:creator)";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		EventModel obj = (EventModel) model;

		// set parameters here
if (obj.getIdProject() != Integer.MIN_VALUE) {
			st.setObject("id_project", obj.getIdProject());
		} else {
			st.setObject("id_project", null);
}
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
}
if (obj.getIdTask() != Integer.MIN_VALUE) {
			st.setObject("id_task", obj.getIdTask());
		} else {
			st.setObject("id_task", null);
}
if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
			st.setObject("id_type", null);
}
if (obj.getIdPlace() != Integer.MIN_VALUE) {
			st.setObject("id_place", obj.getIdPlace());
		} else {
			st.setObject("id_place", null);
}
if (obj.getIdVenue() != Integer.MIN_VALUE) {
			st.setObject("id_venue", obj.getIdVenue());
		} else {
			st.setObject("id_venue", null);
}
if (obj.getPlanStartTime() != null) {
			st.setObject("plan_start_time", obj.getPlanStartTime());
		} else {
			st.setObject("plan_start_time", null);
}
if (obj.getPlanEndTime() != null) {
			st.setObject("plan_end_time", obj.getPlanEndTime());
		} else {
			st.setObject("plan_end_time", null);
}
if (obj.getRealStartTate() != null) {
			st.setObject("real_start_tate", obj.getRealStartTate());
		} else {
			st.setObject("real_start_tate", null);
}
if (obj.getRealEndTime() != null) {
			st.setObject("real_end_time", obj.getRealEndTime());
		} else {
			st.setObject("real_end_time", null);
}
		if (obj.getNeedApprovalSet()) {
			st.setObject("need_approval", obj.getNeedApproval());
		} else {
			st.setObject("need_approval", null);
}
		if (obj.getIsEventSet()) {
			st.setObject("is_event", obj.getIsEvent());
		} else {
			st.setObject("is_event", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
			st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
			st.setObject("notification", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
			st.setObject("creator", null);
}
	

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genUpdateStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_event_update(:id,:id_project,:name,:code,:description,:id_task,:id_type,:id_place,:id_venue,:plan_start_time,:plan_end_time,:real_start_tate,:real_end_time,:need_approval,:is_event,:status,:is_draft,:notification,:updator,:deleted,:deletion_time)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		EventModel obj = (EventModel) model;

		// set parameters here
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
			st.setObject("id", null);
}
if (obj.getIdProject() != Integer.MIN_VALUE) {
			st.setObject("id_project", obj.getIdProject());
		} else {
			st.setObject("id_project", null);
}
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
}
if (obj.getIdTask() != Integer.MIN_VALUE) {
			st.setObject("id_task", obj.getIdTask());
		} else {
			st.setObject("id_task", null);
}
if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
			st.setObject("id_type", null);
}
if (obj.getIdPlace() != Integer.MIN_VALUE) {
			st.setObject("id_place", obj.getIdPlace());
		} else {
			st.setObject("id_place", null);
}
if (obj.getIdVenue() != Integer.MIN_VALUE) {
			st.setObject("id_venue", obj.getIdVenue());
		} else {
			st.setObject("id_venue", null);
}
if (obj.getPlanStartTime() != null) {
			st.setObject("plan_start_time", obj.getPlanStartTime());
		} else {
			st.setObject("plan_start_time", null);
}
if (obj.getPlanEndTime() != null) {
			st.setObject("plan_end_time", obj.getPlanEndTime());
		} else {
			st.setObject("plan_end_time", null);
}
if (obj.getRealStartTate() != null) {
			st.setObject("real_start_tate", obj.getRealStartTate());
		} else {
			st.setObject("real_start_tate", null);
}
if (obj.getRealEndTime() != null) {
			st.setObject("real_end_time", obj.getRealEndTime());
		} else {
			st.setObject("real_end_time", null);
}
		if (obj.getNeedApprovalSet()) {
			st.setObject("need_approval", obj.getNeedApproval());
		} else {
			st.setObject("need_approval", null);
}
		if (obj.getIsEventSet()) {
			st.setObject("is_event", obj.getIsEvent());
		} else {
			st.setObject("is_event", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
			st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
			st.setObject("notification", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
			st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
			st.setObject("deleted", null);
}
if (obj.getDeletionTime() != null) {
			st.setObject("deletion_time", obj.getDeletionTime());
		} else {
			st.setObject("deletion_time", null);
}

	
		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genDeleteStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "select sp_event_delete(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

        EventModel obj = (EventModel) query;

		// set primary keys
st.setObject("id", obj.getId());


		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genCountStatement(Connection dbConn,
			IModelExt input) throws SQLException {
		String sql = "SELECT sp_event_count(:id,:id_project,:name,:code,:description,:id_task,:id_type,:id_place,:id_venue,:plan_start_timeFrom,:plan_start_timeTo,:plan_end_timeFrom,:plan_end_timeTo,:real_start_tateFrom,:real_start_tateTo,:real_end_timeFrom,:real_end_timeTo,:need_approval,:is_event,:status,:is_draft,:notification,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		EventModelExt obj = (EventModelExt) input;

		// set parameters here
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
            st.setObject("id", null);
}
if (obj.getIdProject() != Integer.MIN_VALUE) {
			st.setObject("id_project", obj.getIdProject());
		} else {
            st.setObject("id_project", null);
}
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
            st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
            st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
            st.setObject("description", null);
}
if (obj.getIdTask() != Integer.MIN_VALUE) {
			st.setObject("id_task", obj.getIdTask());
		} else {
            st.setObject("id_task", null);
}
if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
            st.setObject("id_type", null);
}
if (obj.getIdPlace() != Integer.MIN_VALUE) {
			st.setObject("id_place", obj.getIdPlace());
		} else {
            st.setObject("id_place", null);
}
if (obj.getIdVenue() != Integer.MIN_VALUE) {
			st.setObject("id_venue", obj.getIdVenue());
		} else {
            st.setObject("id_venue", null);
}
if (obj.getPlanStartTimeFrom() != null) {
			st.setObject("plan_start_timeFrom", obj.getPlanStartTimeFrom());
		} else {
			st.setObject("plan_start_timeFrom", null);
		}
		if (obj.getPlanStartTimeTo() != null) {
			st.setObject("plan_start_timeTo", obj.getPlanStartTimeTo());
		} else {
            st.setObject("plan_start_timeTo", null);
}
if (obj.getPlanEndTimeFrom() != null) {
			st.setObject("plan_end_timeFrom", obj.getPlanEndTimeFrom());
		} else {
			st.setObject("plan_end_timeFrom", null);
		}
		if (obj.getPlanEndTimeTo() != null) {
			st.setObject("plan_end_timeTo", obj.getPlanEndTimeTo());
		} else {
            st.setObject("plan_end_timeTo", null);
}
if (obj.getRealStartTateFrom() != null) {
			st.setObject("real_start_tateFrom", obj.getRealStartTateFrom());
		} else {
			st.setObject("real_start_tateFrom", null);
		}
		if (obj.getRealStartTateTo() != null) {
			st.setObject("real_start_tateTo", obj.getRealStartTateTo());
		} else {
            st.setObject("real_start_tateTo", null);
}
if (obj.getRealEndTimeFrom() != null) {
			st.setObject("real_end_timeFrom", obj.getRealEndTimeFrom());
		} else {
			st.setObject("real_end_timeFrom", null);
		}
		if (obj.getRealEndTimeTo() != null) {
			st.setObject("real_end_timeTo", obj.getRealEndTimeTo());
		} else {
            st.setObject("real_end_timeTo", null);
}
		if (obj.getNeedApprovalSet()) {
			st.setObject("need_approval", obj.getNeedApproval());
		} else {
            st.setObject("need_approval", null);
}
		if (obj.getIsEventSet()) {
			st.setObject("is_event", obj.getIsEvent());
		} else {
            st.setObject("is_event", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
            st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
            st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
            st.setObject("notification", null);
}
if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
            st.setObject("createdTo", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
            st.setObject("creator", null);
}
if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
            st.setObject("updatedTo", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
            st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
            st.setObject("deleted", null);
}
if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
            st.setObject("deletion_timeTo", null);
}

	
		return st.getPreparedStatement();
	}

/*
	private String fillHtmlTemplate(String template) {
		String html = template
				.replace(":id", Integer.toString(_id))
.replace(":id_project", Integer.toString(_id_project))
.replace(":name", HtmlUtil.genHtml(_name))
.replace(":code", HtmlUtil.genHtml(_code))
.replace(":description", HtmlUtil.genHtml(_description))
.replace(":id_task", Integer.toString(_id_task))
.replace(":id_type", Integer.toString(_id_type))
.replace(":id_place", Integer.toString(_id_place))
.replace(":id_venue", Integer.toString(_id_venue))
.replace(":plan_start_time", StringUtil.toDateTimeString(_plan_start_time))
.replace(":plan_end_time", StringUtil.toDateTimeString(_plan_end_time))
.replace(":real_start_tate", StringUtil.toDateTimeString(_real_start_tate))
.replace(":real_end_time", StringUtil.toDateTimeString(_real_end_time))
.replace(":need_approval", HtmlUtil.genHtml(_isneed_approvalSet, _need_approval))
.replace(":is_event", HtmlUtil.genHtml(_isis_eventSet, _is_event))
.replace(":status", Integer.toString(_status))
.replace(":is_draft", HtmlUtil.genHtml(_isis_draftSet, _is_draft))
.replace(":notification", Integer.toString(_notification))
.replace(":created", StringUtil.toDateTimeString(_created))
.replace(":creator", Integer.toString(_creator))
.replace(":updated", StringUtil.toDateTimeString(_updated))
.replace(":updator", Integer.toString(_updator))
.replace(":deleted", HtmlUtil.genHtml(_isdeletedSet, _deleted))
.replace(":deletion_time", StringUtil.toDateTimeString(_deletion_time))

				;
		return html;
	}
*/

/*
	private String fillHtmlTemplate(String template) {
		String html = template
				.replace(":Id", Integer.toString(_Id))
.replace(":IdProject", Integer.toString(_IdProject))
.replace(":Name", HtmlUtil.genHtml(_Name))
.replace(":Code", HtmlUtil.genHtml(_Code))
.replace(":Description", HtmlUtil.genHtml(_Description))
.replace(":IdTask", Integer.toString(_IdTask))
.replace(":IdType", Integer.toString(_IdType))
.replace(":IdPlace", Integer.toString(_IdPlace))
.replace(":IdVenue", Integer.toString(_IdVenue))
.replace(":PlanStartTime", StringUtil.toDateTimeString(_PlanStartTime))
.replace(":PlanEndTime", StringUtil.toDateTimeString(_PlanEndTime))
.replace(":RealStartTate", StringUtil.toDateTimeString(_RealStartTate))
.replace(":RealEndTime", StringUtil.toDateTimeString(_RealEndTime))
.replace(":NeedApproval", HtmlUtil.genHtml(_isNeedApprovalSet, _NeedApproval))
.replace(":IsEvent", HtmlUtil.genHtml(_isIsEventSet, _IsEvent))
.replace(":Status", Integer.toString(_Status))
.replace(":IsDraft", HtmlUtil.genHtml(_isIsDraftSet, _IsDraft))
.replace(":Notification", Integer.toString(_Notification))
.replace(":Created", StringUtil.toDateTimeString(_Created))
.replace(":Creator", Integer.toString(_Creator))
.replace(":Updated", StringUtil.toDateTimeString(_Updated))
.replace(":Updator", Integer.toString(_Updator))
.replace(":Deleted", HtmlUtil.genHtml(_isDeletedSet, _Deleted))
.replace(":DeletionTime", StringUtil.toDateTimeString(_DeletionTime))

				;
		return html;
	}
*/

}